#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include <cstdlib>
#include<ctime>
using namespace std;

int Sign = 1;
void Chessboard_Coverage(vector<vector<int>>& ChessBoard, int topRow, int topCol, int SRow, int SCol, int size)
{
	if (size == 1)
		return;
	int S = size / 2;
	int t = Sign++;
	if (SRow < topRow + S && SCol < topCol + S)
	{
		Chessboard_Coverage(ChessBoard, topRow, topCol, SRow, SCol, S);
	}
	else
	{
		ChessBoard[topRow + S - 1][topCol + S - 1] = t;
		Chessboard_Coverage(ChessBoard, topRow, topCol, topRow + S - 1, topCol + S - 1, S);
	}
	if (SRow < topRow + S && SCol >= topCol + S)
	{
		Chessboard_Coverage(ChessBoard, topRow, topCol + S, SRow, SCol, S);
	}
	else
	{
		ChessBoard[topRow + S - 1][topCol + S] = t;
		Chessboard_Coverage(ChessBoard, topRow, topCol + S, topRow + S - 1, topCol + S, S);
	}
	if (SRow >= topRow + S && SCol < topCol + S)
	{
		Chessboard_Coverage(ChessBoard, topRow+S, topCol, SRow, SCol, S);
	}
	else
	{
		ChessBoard[topRow + S][topCol + S - 1] = t;
		Chessboard_Coverage(ChessBoard, topRow + S, topCol, topRow + S, topCol + S - 1, S);
	}
	if (SRow >= topRow + S && SCol >= topCol + S)
	{
		Chessboard_Coverage(ChessBoard, topRow+S, topCol+S, SRow, SCol, S);
	}
	else
	{
		ChessBoard[topRow + S][topCol + S] = t;
		Chessboard_Coverage(ChessBoard, topRow + S, topCol + S, topRow + S, topCol + S, S);
	}
}
int main()
{
	srand((unsigned)time(NULL));
	int size = 0;
	cout << "Please enter the size of the chessboard:>";
	cin >> size;
	vector<vector<int>> ChessBoard;
	ChessBoard.resize(size);
	for (size_t i = 0; i < size; i++)
	{
		ChessBoard[i].resize(size);
	}
	int SpecialPointRow = rand() % size;
	int SpecialPointCol = rand() % size;
	ChessBoard[SpecialPointRow][SpecialPointCol] = 0;
	Chessboard_Coverage(ChessBoard, 0, 0, SpecialPointRow, SpecialPointCol, size);
	for (size_t i = 0; i < size; i++)
	{
		for (size_t j = 0; j < size; j++)
		{
			printf("%02d ", ChessBoard[i][j]);
		}
		cout << endl;
	}
	return 0;
}
